package com.codechuan.demo.thread;


import com.codechuan.demo.dto.SuccessOrder;

/**
 * @Deprecated 订单缓冲类
 */
public class SynContainer {
    // 缓冲区大小
    SuccessOrder[] successOrders = new SuccessOrder[10];

    // 缓冲区大小计数
    int count = 0;

    public synchronized void setSuccessOrder(SuccessOrder successOrder) {
        // 判断容器是否满了
        if (count == successOrders.length - 1) {
            // 通知消费者消费,生产者等待生产
            System.out.println("等待消费");
        }else {
            // 如果没有满,就往里面放匹配成功的订单
            count++;
            successOrders[count] = successOrder;
        }
    }

    public synchronized SuccessOrder getSuccessOrder() {
        if (count != 0) {
            // 等待生产者,放入匹配成功订单数据
            SuccessOrder successOrder = successOrders[count];
            count--;
            return successOrder;
        }
       return null;
    }

}
